function [ Tag_st_pos,Tag_end_pos ] = tracedatsegment( dat,tag,bck )
%UNTITLED3 �˴���ʾ�йش˺�����ժҪ
%   �˴���ʾ��ϸ˵��

%make dat a vector  
dat = dat(:);
Tag_st_pos = [];
Tag_end_pos = [];
Tag_ix = 1;
First_tag = 0;
First_bck = 1;
if(dat(1,1) == tag )
    First_tag = 1;
    Tag_st_pos(1,1) = 1;
    Tag_ix = 1;
else
    First_bck = 1;
end
if(length(dat)>=2)

    for ix = 2:length(dat)
        if(First_tag )
            if( dat(ix,1) == bck)
               Tag_end_pos(Tag_ix,1) = ix -1;
                Tag_ix = Tag_ix + 1;
                First_tag = 0;
            end
        else
            if( dat(ix,1) == tag)
                Tag_st_pos(Tag_ix,1) = ix ;
                First_tag =1;
            end 
        end
    end
else
    Tag_end_pos(1,1) = 1;
end

if( First_tag ) 
    Tag_end_pos(Tag_ix,1) = ix ; 
end

end

